package org.tigris.subversion.svnant.commands;

import java.io.File;
import java.net.MalformedURLException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.EnumeratedAttribute;
import org.tigris.subversion.svnant.SvnAntUtilities;
import org.tigris.subversion.svnclientadapter.ISVNClientAdapter;
import org.tigris.subversion.svnclientadapter.ISVNInfo;
import org.tigris.subversion.svnclientadapter.SVNClientException;
import org.tigris.subversion.svnclientadapter.SVNRevision;
import org.tigris.subversion.svnclientadapter.SVNRevision.Number;
import org.tigris.subversion.svnclientadapter.SVNUrl;

public class SingleInfo extends SvnCommand
{
  private static final String MSG_FAILED_TO_ACCESS_PROPERTIES = "Failed to access subversion 'info' properties";
  private static final String MSG_PROPERTY_NOT_IMPLEMENTED = "Property '%s' not implemented";
  private static final String MSG_PROPERTY_NOT_RECOGNIZED = "Property '%s' not recognized";
  private static final String MSG_UNVERSIONED_RESOURCE = "%s - Not a versioned resource";
  private static final String PROP_PATH = "path";
  private static final String PROP_URL = "url";
  private static final String PROP_REPOURL = "repourl";
  private static final String PROP_REPOUUID = "repouuid";
  private static final String PROP_REV = "revision";
  private static final String PROP_NODEKIND = "nodekind";
  private static final String PROP_SCHEDULE = "schedule";
  private static final String PROP_AUTHOR = "author";
  private static final String PROP_LASTREV = "lastRevision";
  private static final String PROP_LASTDATE = "lastDate";
  private static final String PROP_NAME = "name";
  private static final String PROP_LASTTEXTUPDATE = "lastTextUpdate";
  private static final String PROP_LASTPROPUPDATE = "lastPropUpdate";
  private static final String PROP_CHECKSUM = "checksum";
  private static final String[] PROP_ALL = { "path", "url", "repouuid", "revision", "nodekind", "schedule", "author", "lastRevision", "lastDate", "name", "lastTextUpdate", "lastPropUpdate", "checksum", "repourl" };
  private String target = null;
  private String property = null;
  private PropRequest request = null;

  public void execute()
  {
    Project localProject = getProject();
    try
    {
      ISVNInfo localISVNInfo = acquireInfo();
      if ((localISVNInfo.getRevision() == null) || (SVNRevision.INVALID_REVISION.equals(localISVNInfo.getRevision())))
        throw ex("%s - Not a versioned resource", new Object[] { this.target });
      String str = getValue(localISVNInfo, this.request.getValue());
      localProject.setProperty(this.property, str);
      verbose("%s : %s", new Object[] { this.property, str });
    }
    catch (Exception localException)
    {
      throw ex(localException, "Failed to access subversion 'info' properties", new Object[0]);
    }
  }

  private ISVNInfo acquireInfo()
    throws SVNClientException
  {
    File localFile = new File(Project.translatePath(this.target));
    if (localFile.exists())
      return getClient().getInfo(localFile);
    try
    {
      SVNUrl localSVNUrl = new SVNUrl(this.target);
      return getClient().getInfo(localSVNUrl);
    }
    catch (MalformedURLException localMalformedURLException)
    {
    }
    return getClient().getInfo(localFile);
  }

  private String getValue(ISVNInfo paramISVNInfo, String paramString)
  {
    Object localObject = null;
    File localFile;
    if ("path".equals(paramString))
    {
      localFile = paramISVNInfo.getFile();
      if (localFile != null)
        localObject = localFile.getAbsolutePath();
      else
        localObject = paramISVNInfo.getUrl().getLastPathSegment();
    }
    else if ("name".equals(paramString))
    {
      localFile = paramISVNInfo.getFile();
      if (localFile != null)
        localObject = localFile.getName();
      else
        localObject = paramISVNInfo.getUrl().getLastPathSegment();
    }
    else if ("repourl".equals(paramString))
    {
      localObject = paramISVNInfo.getRepository();
    }
    else if ("url".equals(paramString))
    {
      localObject = paramISVNInfo.getUrl();
    }
    else if ("repouuid".equals(paramString))
    {
      localObject = paramISVNInfo.getUuid();
    }
    else if ("revision".equals(paramString))
    {
      localObject = paramISVNInfo.getRevision();
    }
    else if ("nodekind".equals(paramString))
    {
      localObject = paramISVNInfo.getNodeKind();
    }
    else if ("schedule".equals(paramString))
    {
      localObject = paramISVNInfo.getSchedule();
    }
    else if ("author".equals(paramString))
    {
      localObject = paramISVNInfo.getLastCommitAuthor();
    }
    else if ("lastRevision".equals(paramString))
    {
      localObject = paramISVNInfo.getLastChangedRevision();
    }
    else if ("lastDate".equals(paramString))
    {
      localObject = paramISVNInfo.getLastChangedDate();
    }
    else if ("lastTextUpdate".equals(paramString))
    {
      localObject = paramISVNInfo.getLastDateTextUpdate();
    }
    else if ("lastPropUpdate".equals(paramString))
    {
      localObject = paramISVNInfo.getLastDatePropsUpdate();
    }
    else if ("checksum".equals(paramString))
    {
      warning("    Property '%s' not implemented", new Object[] { paramString });
    }
    else
    {
      warning("    Property '%s' not recognized", new Object[] { paramString });
    }
    if (localObject == null)
      localObject = "";
    return (String)String.valueOf(localObject);
  }

  protected void validateAttributes()
  {
    SvnAntUtilities.attrNotEmpty("target", this.target);
    SvnAntUtilities.attrNotEmpty("property", this.property);
    SvnAntUtilities.attrNotNull("request", this.request);
  }

  public void setTarget(String paramString)
  {
    this.target = paramString;
    if ((this.target != null) && (this.target.length() == 0))
      this.target = null;
  }

  public void setRequest(PropRequest paramPropRequest)
  {
    this.request = paramPropRequest;
  }

  public void setProperty(String paramString)
  {
    this.property = paramString;
    if ((this.property != null) && (this.property.length() == 0))
      this.property = null;
  }

  public static class PropRequest extends EnumeratedAttribute
  {
    public String[] getValues()
    {
      return SingleInfo.PROP_ALL;
    }
  }
}

/* Location:           C:\Users\Administrator\Desktop\svnant.jar
 * Qualified Name:     org.tigris.subversion.svnant.commands.SingleInfo
 * JD-Core Version:    0.6.0
 */